
package com.insigma.business.common.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.insigma.business.gateway.template.BaseGatewayManagerImpl;
import com.insigma.business.qrcode.common.vo.BaseResponse;
import com.insigma.business.qrcode.soldier._consumer.SecurityConsumer;
import com.insigma.business.qrcode.soldier.dto.GatewayTypeEnum;
import com.insigma.business.qrcode.soldier.dto.LoggedInPersistentSoldierDTO;
import com.insigma.business.common.dto.LoggedInSoldierPersistentVO;
import com.insigma.business.qrcode.soldier.dto.RequestObjFO;
import com.insigma.business.gateway.template.CheckValidManager;
import com.insigma.business.common.service.SoldierGatewayManager;
import com.insigma.business.qrcode.soldier.util.SoldierConstant;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;


@Service("soldierGatewayAndCheckManager")
@DependsOn(value = "springContextHolder")
public class SoldierGatewayManagerImpl extends BaseGatewayManagerImpl implements
        SoldierGatewayManager, CheckValidManager {
    @Autowired
    SecurityConsumer securityConsumer;

    @PostConstruct
    public void init() {
        super.init(GatewayTypeEnum.SOLDIER);
    }


    @Override
    public void checkRequestParam(final RequestObjFO requestObj, final boolean isVerifySign) {
        super.checkRequestParam(requestObj, GatewayTypeEnum.SOLDIER, isVerifySign);
    }


    @Override
    public void checkHack(String operation, String token) {


    }


    @Override
    public boolean isVisitorOperation(RequestObjFO requestObj) {
        if (StringUtils.equals(SoldierConstant.RPC_SERVICE_INTERFACE_PWD_RETRIEVE, requestObj.getOperation())
                || StringUtils.equals(SoldierConstant.RPC_SERVICE_INTERFACE_ALIPAY_LIFE_REGISTER_OR_LOGIN, requestObj.getOperation())
                || StringUtils.equals(SoldierConstant.RPC_SERVICE_INTERFACE_ALIPAY_LIFE_OAUTH2_URL, requestObj.getOperation())
                || StringUtils.equals(SoldierConstant.RPC_SERVICE_INTERFACE_MARKETING_DELIVERY_URL, requestObj.getOperation())
                || StringUtils.equals(SoldierConstant.RPC_SERVICE_INTERFACE_ZLB_LOGIN, requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.buried.point.week.section.add", requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.digital.social.stats", requestObj.getOperation())
                || StringUtils.equals("8101.open.yh.soldier.business.apply.certificate", requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.soldier.come.task.view", requestObj.getOperation())
                || StringUtils.equals("8101.gov.ss.soldier.come.task.send.issue", requestObj.getOperation())
                || StringUtils.equals("8101.gov.ss.soldier.come.task.complete", requestObj.getOperation())
                || StringUtils.equals("8101.open.ss.jsc.data.jd.view", requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.care.welfare.merchant.top", requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.care.welfare.merchant.view", requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.care.welfare.merchant.evaluation.search", requestObj.getOperation())
                || StringUtils.equals("8101.all.ss.common.area.switch", requestObj.getOperation())
                || StringUtils.equals("8101.open.ss.jsc.data.jd.modify", requestObj.getOperation())
                || StringUtils.equals(SoldierConstant.RPC_SERVICE_INTERFACE_XCX_LOGIN, requestObj.getOperation())
        ) {
            return true;
        }

       /* if(StringUtils.equals(ConsumerConstant.RPC_SERVICE_INTERFACE_CUSTOMER_SEND_SMS, requestObj.getOperation())) {
            if(requestObj.getBizReqData().contains(SmsPurposeEnum.RETRIEVE_PWD.name())
               ||requestObj.getBizReqData().contains(SmsPurposeEnum.REGISTER_OR_LOGIN.name())){
                return true;
            }
        }*/

        return false;
    }


    @Override
    public BaseResponse executeService(final RequestObjFO requestObj) {
        return super.executeService(requestObj, GatewayTypeEnum.SOLDIER);
    }



    @Override
    public LoggedInSoldierPersistentVO getLoggedInSoldierPersistentInfoByToken(final String token) {
        final LoggedInPersistentSoldierDTO loggedInPersistentDTO = securityConsumer.getLoggedInPersistentSoldier(token).getDto();
        if (loggedInPersistentDTO != null) {
            final LoggedInSoldierPersistentVO loggedInPersistentVO = new LoggedInSoldierPersistentVO();
            BeanUtil.copyProperties(loggedInPersistentDTO, loggedInPersistentVO);
            return loggedInPersistentVO;
        } else {
            return null;
        }
    }

}
